package com.ruoyi.whole.service.impl;

import java.util.List;

import com.ruoyi.evaluate.infoprojectevaluate.domain.InfoProjectEvaluate;
import com.ruoyi.whole.domain.InfoBulkIndexAddVo;
import com.ruoyi.whole.domain.InfoWholePlan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.whole.mapper.InfoWholeIndexMapper;
import com.ruoyi.whole.domain.InfoWholeIndex;
import com.ruoyi.whole.service.IInfoWholeIndexService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * 目标管理-部门整体-指标详情Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-09
 */
@Service
public class InfoWholeIndexServiceImpl implements IInfoWholeIndexService {
    @Autowired
    private InfoWholeIndexMapper infoWholeIndexMapper;

    /**
     * 查询目标管理-部门整体-指标详情
     *
     * @param id 目标管理-部门整体-指标详情主键
     * @return 目标管理-部门整体-指标详情
     */
    @Override
    public InfoWholeIndex selectInfoWholeIndexById(Long id) {
        return infoWholeIndexMapper.selectInfoWholeIndexById(id);
    }

    /**
     * 查询目标管理-部门整体-指标详情列表
     *
     * @param infoWholeIndex 目标管理-部门整体-指标详情
     * @return 目标管理-部门整体-指标详情
     */
    @Override
    public List<InfoWholeIndex> selectInfoWholeIndexList(InfoWholeIndex infoWholeIndex) {
        return infoWholeIndexMapper.selectInfoWholeIndexList(infoWholeIndex);
    }

    /**
     * 新增目标管理-部门整体-指标详情
     *
     * @param infoWholeIndex 目标管理-部门整体-指标详情
     * @return 结果
     */
    @Override
    public int insertInfoWholeIndex(InfoWholeIndex infoWholeIndex) {
        return infoWholeIndexMapper.insertInfoWholeIndex(infoWholeIndex);
    }

    /**
     * 修改目标管理-部门整体-指标详情
     *
     * @param infoWholeIndex 目标管理-部门整体-指标详情
     * @return 结果
     */
    @Override
    public int updateInfoWholeIndex(InfoWholeIndex infoWholeIndex) {
        return infoWholeIndexMapper.updateInfoWholeIndex(infoWholeIndex);
    }

    /**
     * 批量删除目标管理-部门整体-指标详情
     *
     * @param ids 需要删除的目标管理-部门整体-指标详情主键
     * @return 结果
     */
    @Override
    public int deleteInfoWholeIndexByIds(Long[] ids) {
        return infoWholeIndexMapper.deleteInfoWholeIndexByIds(ids);
    }

    /**
     * 删除目标管理-部门整体-指标详情信息
     *
     * @param id 目标管理-部门整体-指标详情主键
     * @return 结果
     */
    @Override
    public int deleteInfoWholeIndexById(Long id) {
        return infoWholeIndexMapper.deleteInfoWholeIndexById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchInsert(InfoBulkIndexAddVo infoBulkIndexAddVo) {
        try {
            List<InfoWholeIndex> infoWholeIndices = infoBulkIndexAddVo.getInfoWholeIndices();
            for (InfoWholeIndex infoWholeIndex : infoWholeIndices) {
                infoWholeIndex.setId(null);
                infoWholeIndex.setWholeId(infoBulkIndexAddVo.getWholeId());
                infoWholeIndex.setDeptId(infoBulkIndexAddVo.getDeptId());
                infoWholeIndexMapper.insertInfoWholeIndex(infoWholeIndex);
            }
            return 1;
        } catch (Exception e) {
            System.out.println(e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
    }

    @Override
    public List<InfoWholeIndex> selectInfoWholeIndicesId(Long deptId) {
        return infoWholeIndexMapper.selectInfoWholeIndicesId(deptId);
    }

    @Override
    public InfoWholeIndex xgList(InfoWholeIndex infoWholeIndex) {
        infoWholeIndexMapper.updateInfoWholeIndex(infoWholeIndex);
        return infoWholeIndexMapper.selectInfoWholeIndexById(infoWholeIndex.getId());
    }

    @Override
    public int uploadFiles(InfoWholeIndex infoWholeIndex) {
        Long id=infoWholeIndex.getId();
        //读取这个文件地址
        String fileUrl = infoWholeIndex.getReportUrl();
        String fileName=infoWholeIndex.getReportName();
        InfoWholeIndex infoWholeIndex1=infoWholeIndexMapper.selectInfoWholeIndexById(id);
        infoWholeIndex1.setReportUrl(fileUrl);
        infoWholeIndex1.setReportName(fileName);
        int i=infoWholeIndexMapper.updateInfoWholeIndex(infoWholeIndex1);
        return i;
    }
}
